package jd.client.impl;

import java.io.IOException;

import jd.client.util.IOUtil;

import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

/**
 * Main class for JDownloader remote controlling.
 * 
 * @author Denis Migol
 * 
 */
public class HttpJDClient extends JDClientBase {

	private final HttpClient httpClient = new DefaultHttpClient();

	/**
	 * The constructor
	 */
	public HttpJDClient() {
		super();
	}

	/**
	 * 
	 * @param host
	 */
	public HttpJDClient(final String host) {
		super(host);
	}

	/**
	 * 
	 * @param port
	 */
	public HttpJDClient(final int port) {
		super(port);
	}

	/**
	 * 
	 * @param host
	 * @param port
	 */
	public HttpJDClient(final String host, final int port) {
		super(host, port);
	}

	/**
	 * @return the client
	 */
	public HttpClient getHttpClient() {
		return httpClient;
	}

	/**
	 * 
	 * @param url
	 * @return
	 * @throws IOException
	 */
	@Override
	protected String requestToString(final String url) throws IOException {
		return new String(IOUtil.toByteArray(getHttpClient().execute(new HttpGet(url)).getEntity().getContent()));
	}

}
